<template>
    <div id="cc">
        <div style="position: sticky;top:0;z-index: 9999;background: #fff;">
            <div style="display: flex;flex-direction: row;height: 40px;">
                <div
                        style="display: flex;justify-content: center;align-items: center;width: 25vw;
                        font-family: PingFangSC-Regular;font-size: 14px;"
                        :style="{borderBottom:activeStep==index?'2px solid #454592':'1px solid #ddd',color:activeStep==index?'#454592':'#333'}"
                        v-for="(item,index) in ['基本','疾病','合病症','治疗']"
                        @click="privilegeHeadClick('anchor-'+index)">
                    <span>
                      {{item}}
                    </span>
                </div>
            </div>
        </div>
        <div class="wrapper">
            <!--基本信息-->
            <div id="anchor-0" class="privilege-wrap">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        基本信息
                    </div>
                </div>
                <!--field-->
                <div class="field_item">
                    <div class="field_title">
                        年龄
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B02" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        体重
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B04" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        身高（cm）
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B07" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        BMI（kg/m2）
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B05" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        性别
                    </div>
                    <div>
                        <Cell is-link :title="form.tabBasic.B03" @click="genderShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        地点
                    </div>
                    <div>
                        <Cell is-link :title="form.tabBasic.B01" @click="B01Show=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        透龄 （年）
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B06" type="number"/>
                    </div>
                </div>

            </div>
            <Overlay :show="genderShow">
                <RadioList :fullList="genderOptions" :checked="form.tabBasic.B03" @confirm="genderConfirm"
                           @cancel="genderShow=false"/>
            </Overlay>
            <Overlay :show="B01Show">
                <RadioList :fullList="B01Options" :checked="form.tabBasic.B01" @confirm="B01Confirm"
                           @cancel="B01Show=false"/>
            </Overlay>


            <!--基本信息-->
            <!--疾病信息-->
            <div class="mt20 privilege-wrap" id="anchor-1">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        疾病信息
                    </div>
                </div>
                <!--field-->

                <div class="field_item">
                    <div class="field_title">
                        血钙水平（mmol/L）
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D26" type="number"/>
                    </div>
                </div>

                <div class="field_item">
                    <div class="field_title">
                        血磷水平（mmol/L）
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D27" type="number"/>
                    </div>
                </div>


                <div class="field_item">
                    <div class="field_title">
                        iPTH水平（pg/mL）
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D28" type="number"/>
                    </div>
                </div>


                <div class="field_item">
                    <div class="field_title">
                        血肌酐（mg/dL）
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D18" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        eGFR（ml/min/1.73m2)
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D30" type="number"/>
                    </div>
                </div>

                <div class="field_item">
                    <div class="field_title">
                        CKD分期
                    </div>
                    <div>
                        <Cell is-link :title="form.tabDisease.D29" @click="D29Show=true"/>
                    </div>
                </div>

                <div class="field_item">
                    <div class="field_title">
                        透析方式
                    </div>
                    <div>
                        <Cell is-link :title="form.tabDisease.C04" @click="C04Show=true"/>
                    </div>
                </div>


            </div>
            <Overlay :show="D29Show">
                <RadioList :fullList="D29Options" :checked="form.tabDisease.D29" @confirm="D29Confirm"
                           @cancel="D29Show=false"/>
            </Overlay>
            <Overlay :show="C04Show">
                <RadioList :fullList="C04Options" :checked="form.tabDisease.C04" @confirm="C04Confirm"
                           @cancel="C04Show=false"/>
            </Overlay>

            <!--疾病信息-->
            <!--合并症信息-->
            <div class="mt20 privilege-wrap" id="anchor-2">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        合并症信息
                    </div>
                </div>
                <!--field-->

                <div class="field_item">
                    <div class="field_title">
                        伴发疾病及既往史(多选)
                    </div>
                    <div>
                        <Cell is-link :title="form.tabComplication.C15.join(',')" @click="diseaseHistoryShow=true"/>
                    </div>
                </div>
                <div v-if="form.tabComplication.C15.includes('高血压')">
                    <div class="title_sub">
                        高血压
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            舒张压(mmHg)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C14" type="number"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            收缩压(mmHg)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C13" type="number"/>
                        </div>
                    </div>
                </div>
                <div v-if="form.tabComplication.C15.includes('糖尿病')">
                    <div class="title_sub">
                        糖尿病
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            当前治疗方案
                        </div>
                        <div>
                            <Cell is-link :title="form.tabComplication.C01"
                                  @click="currentTherapeuticShow=true"/>
                        </div>
                    </div>
                    <div class="field_item" v-if="form.tabComplication.C01.includes('仅OAD')">
                        <div class="field_title">
                            仅二甲双胍控制
                        </div>
                        <div>
                            <Cell is-link :title="form.tabComplication.C02"
                                  @click="metformincontrolShow=true"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            空腹血糖(mmol/L)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C10" type="number"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            餐后血糖(mmol/L)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C11" type="number"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            糖化血红蛋白(%)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C12" type="number"/>
                        </div>
                    </div>
                </div>

            </div>
            <Overlay :show="diseaseHistoryShow">
                <CheckboxList :fullList="diseaseHistoryOptions" :checked="form.tabComplication.C15"
                              @confirm="diseaseHistoryconfirm" @cancel="diseaseHistoryShow = false"/>
            </Overlay>
            <Overlay :show="currentTherapeuticShow">
                <RadioList :fullList="currentTherapeuticOption" :checked="form.tabComplication.C01" @confirm="currentTherapeuticConfirm"
                           @cancel="currentTherapeuticShow=false"/>
            </Overlay>
            <Overlay :show="metformincontrolShow">
                <RadioList :fullList="metformincontrolOptions" :checked="form.tabComplication.C02" @confirm="metformincontrolConfirm"
                           @cancel="metformincontrolShow=false"/>
            </Overlay>

            <!--合并症信息-->
            <!--治疗信息-->
            <div class="mt20 privilege-wrap" id="anchor-3">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        治疗信息
                    </div>
                </div>
                <!--field-->
                <div class="field_item">
                    <div class="field_title">
                        上次治疗方案（可多选）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T09.join(',')" @click="T09Show=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        当前方案（可多选）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T05.join(',')" @click="T05Show=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        起始诺维乐剂量（mg）
                    </div>
                    <div>
                        <Field v-model="form.treatment.T07" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        目前诺维乐剂量（mg）
                    </div>
                    <div>
                        <Field v-model="form.treatment.T06" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        使用诺维乐治疗周期
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T17"
                              @click="T17Show=true"/>
                    </div>
                </div>
            </div>
            <Overlay :show="T17Show">
                <RadioList :fullList="T17Options" :checked="form.treatment.T17" @confirm="T17Confirm"
                           @cancel="T17Show=false"/>
            </Overlay>
            <Overlay :show="T09Show">
                <CheckboxList :fullList="T09Options" :checked="form.treatment.T09"
                              @confirm="T09confirm" @cancel="T09Show = false"/>
            </Overlay>
            <Overlay :show="T05Show">
                <CheckboxList :fullList="T05Options" :checked="form.treatment.T05"
                              @confirm="T05confirm" @cancel="T05Show = false"/>
            </Overlay>



            <!--治疗信息-->
            <!--保存按钮-->
            <div class="submit">
                <div class="submit_btn" @click="save">
                    保存
                </div>
            </div>
            <div class="submit_btn2" @click="submit">
                提交
            </div>
        </div>
        <div>
            <img :src="cloud_img" style="width: 100%"/>
        </div>
    </div>

</template>

<script>
    import {
        Field,
        Cell,
        CellGroup,
        Popup,
        Picker,
        Toast,
        Overlay,
        Checkbox,
        CheckboxGroup
    } from 'vant';
    import cloud_img from '@assets/image/cloud.svg'
    import RadioList from "@components/snfRadioList/index";
    import CheckboxList from "@components/snfCheckboxList/index";
    const genderOptions = ['男', '女']
    const B01Options = ['门诊', '病房']
    const D29Options = ['1', '2', '3', '4', '5', '5d']
    const C04Options = ['血液透析', '腹膜透析', '其他透析方式']
    const diseaseHistoryOptions = ['糖尿病', '高血压', '胃肠道出血史', '痛风史', '哮喘', '多血管床病变', '其它', '无']
    const currentTherapeuticOption = ['新诊断/未治疗', '仅OAD', '基础+OAD', '基础追加', '基础餐时', '短期强化', '其他']
    const metformincontrolOptions = ['是', '否']
    const T06Options = ['外科VTE预防：2000Axa IU q24h , 皮下注射', '外科VTE预防：4000Axa IU q24h , 皮下注射', '内科VTE预防：4000Axa IU q24h , 皮下注射', 'DVT/PE治疗：150Axa IU/Kg q24h ,皮下注射', 'DVT/PE治疗：100Axa IU/Kg q12h ,皮下注射']
    const T09Options = ['碳酸钙', '醋酸钙', '醋酸镁', '碳酸镧', '氢氧化铝', '其他']
    const C01Options = ['新诊断/未治疗', '仅OAD', '基础+OAD', '基础追加', '基础餐时', '短期强化', '其他']
    const T17Options = ['2周', '4周', '6周', '8周', '12周', '16周', '24周', '≥24周']
    const T05Options = ['诺维乐®']

    export default {
        name: "add",
        props: {
            scheduleId: String,
            tabActive: Number
        },
        components: {
            RadioList,
            CheckboxList,
            Field,
            Cell,
            Popup,
            Picker,
            Toast,
            Overlay,
            Checkbox,
            CheckboxGroup,
            CellGroup
        },
        data() {
            return {
                active: '',
                activeStep: '',
                form: {
                    finish: false,
                    callPlanId: this.scheduleId,
                    prodName: '诺维乐',
                    prodId: 'RENVEL',
                    tabBasic: {
                        B02: '',
                        B03: '',
                        B04: '',
                        B07: '',
                        B05: '',
                        B01: '',
                        B06: ''
                    },
                    tabDisease: {
                        D26: '',
                        D27: '',
                        D28: '',
                        D18: '',
                        D30: '',
                        D29: '',
                        C04: ''
                    },
                    tabComplication: {
                        C15: [],
                        C14: '',
                        C13: '',
                        C01: '',
                        C02: '',
                        C10: '',
                        C11: '',
                        C12: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T07: '',
                        T06: '',
                        T17: ''
                    }
                },
                genderShow: false,
                B01Show: false,
                D29Show: false,
                C04Show: false,
                diseaseHistoryShow: false,
                T09Show: false,
                C01Show: false,
                T17Show: false,
                currentTherapeuticShow: false,
                metformincontrolShow: false,
                T06Show: false,
                genderOptions: genderOptions,
                B01Options: B01Options,
                D29Options: D29Options,
                C04Options: C04Options,
                T17Options: T17Options,
                diseaseHistoryOptions: diseaseHistoryOptions,
                T09Options: T09Options,
                C01Options: C01Options,
                currentTherapeuticOption: currentTherapeuticOption,
                metformincontrolOptions: metformincontrolOptions,
                T06Options: T06Options,
                T05Options: T05Options,
                T05Show: false,
                cloud_img: cloud_img
            }
        },
        methods: {
            T05confirm(value, index) {
                this.form.treatment.T05 = value
                this.T05Show = false
            },
            T09confirm(value, index) {
                this.form.treatment.T09 = value
                this.T09Show = false
            },
            diseaseHistoryconfirm(value, index) {
                this.form.tabComplication.C15 = value
                this.diseaseHistoryShow = false
            },
            onScroll(e) {
                let scrollItems = document.querySelectorAll(".privilege-wrap");
                for (let i = scrollItems.length - 1; i >= 0; i--) {
                    // 判断滚动条滚动距离是否大于当前滚动项可滚动距离
                    let judge =
                        e.target.scrollTop >=
                        scrollItems[i].offsetTop - scrollItems[0].offsetTop;
                    if (judge) {
                        this.activeStep = i;
                        this.active = this.activeStep
                        break;
                    }
                }
            },
            privilegeHeadClick(anchor) {
                this.$nextTick(() => {
                    document.querySelector(`#${anchor}`).scrollIntoView({
                        behavior: "smooth", // 平滑过渡
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
            },
            // electrocardiogramtoggle(index){
            //     this.$refs.electrocardiogramtogglecheckboxes[index].toggle();
            // },
            toggle(index) {
                this.$refs.checkboxes[index].toggle();
            },
            T09toggle(index) {
                this.$refs.T09checkboxes[index].toggle();
            },
            T05toggle(index) {
                this.$refs.T05checkboxes[index].toggle();
            },
            genderConfirm(value, index) {
                this.form.tabBasic.B03 = value
                this.genderShow = false
            },
            B01Confirm(value, index) {
                this.form.tabBasic.B01 = value
                this.B01Show = false
            },

            D29Confirm(value, index) {
                this.form.tabDisease.D29 = value
                this.D29Show = false
            },
            T17Confirm(value, index) {
                this.form.treatment.T17 = value
                this.T17Show = false
            },

            C04Confirm(value, index) {
                this.form.tabDisease.C04 = value
                this.C04Show = false
            },
            currentTherapeuticConfirm(value, index) {
                this.form.tabComplication.C01 = value
                this.currentTherapeuticShow = false
            },
            metformincontrolConfirm(value, index) {
                this.form.tabComplication.C02 = value
                this.metformincontrolShow = false
            },
            T06Confirm(value, index) {
                this.form.treatment.T06 = value
                this.T06Show = false
            },
            saveCheck() {
                if (!this.form.tabBasic.B01) {
                    alert("请选择地点！")
                    return false
                }
                if (!this.form.tabBasic.B02) {
                    alert("请输入年龄！")
                    return false
                }
                if (!this.form.tabBasic.B03) {
                    alert("请选择性别！")
                    return false
                }
                if (!this.form.tabBasic.B04) {
                    alert("请输入体重！")
                    return false
                }
                if (!this.form.tabBasic.B05) {
                    alert("请输入BMI！")
                    return false
                }
                if (!this.form.tabBasic.B06) {
                    alert("请选择病程！")
                    return false
                }
                if (!this.form.tabBasic.B07) {
                    alert("请输入身高！")
                    return false
                }
                if (!this.form.tabDisease.D26) {
                    alert("请输入血钙水平！")
                    return false
                }
                if (!this.form.tabDisease.D27) {
                    alert("请输入血磷水平！")
                    return false
                }
                if (!this.form.tabDisease.D28) {
                    alert("请输入iPTH水平！")
                    return false
                }
                if (!this.form.tabDisease.D29) {
                    alert("请选择CKD分期！")
                    return false
                }
                if (!this.form.tabDisease.D30) {
                    alert("请输入eGFR！")
                    return false
                }
                if (!this.form.tabDisease.D18) {
                    alert("请输入血肌酐！")
                    return false
                }
                if (!this.form.tabDisease.C04) {
                    alert("请选择透析方式！")
                    return false
                }
                if (this.form.tabComplication.C15.length < 1) {
                    alert("请选择伴发疾病及既往史！")
                    return false
                }
                if (this.form.tabComplication.C15.includes('高血压')) {
                    if (!this.form.tabComplication.C13) {
                        alert("请输入收缩压！")
                        return false
                    }
                    if (!this.form.tabComplication.C14) {
                        alert("请输入舒张压！")
                        return false
                    }
                }
                if (this.form.tabComplication.C15.includes('糖尿病')) {
                    if (!this.form.tabComplication.C01) {
                        alert("请选择当前治疗方案！")
                        return false
                    }
                    if (!this.form.tabComplication.C10) {
                        alert("请输入空腹血糖！")
                        return false
                    }
                    if (!this.form.tabComplication.C11) {
                        alert("请输入餐后血糖！")
                        return false
                    }
                    if (!this.form.tabComplication.C12) {
                        alert("请输入糖化血红蛋白！")
                        return false
                    }
                }
                if (this.form.tabComplication.C01 == '仅OAD') {
                    if (!this.form.tabComplication.C02) {
                        alert("请选择仅二甲双胍控制！")
                        return false
                    }
                }
                if (this.form.treatment.T09.length < 1) {
                    alert("请选择上次治疗方案！")
                    return false
                }
                if (this.form.treatment.T05.length < 1) {
                    alert("请选择当前方案！")
                    return false
                }
                if (this.form.treatment.T06.length < 1) {
                    alert("请选择目前诺维乐剂量！")
                    return false
                }
                if (this.form.treatment.T07.length < 1) {
                    alert("请输入起始诺维乐剂量！")
                    return false
                }
                if (this.form.treatment.T17.length < 1) {
                    alert("请选择使用诺维乐治疗周期！")
                    return false
                }
                return true
            },
            save() {
                this.form.finish = false
                this.$emit('save', Object.assign({}, this.form))
                this.$nextTick(() => {
                    document.querySelector(`#cc`).scrollIntoView({
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
                this.form = {
                    finish: false,
                    callPlanId: this.scheduleId,
                    prodName: '诺维乐',
                    prodId: 'RENVEL',
                    tabBasic: {
                        B02: '',
                        B03: '',
                        B04: '',
                        B07: '',
                        B05: '',
                        B01: '',
                        B06: ''
                    },
                    tabDisease: {
                        D26: '',
                        D27: '',
                        D28: '',
                        D18: '',
                        D30: '',
                        D29: '',
                        C04: ''
                    },
                    tabComplication: {
                        C15: [],
                        C14: '',
                        C13: '',
                        C01: '',
                        C02: '',
                        C10: '',
                        C11: '',
                        C12: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T07: '',
                        T06: '',
                        T17: ''
                    }
                }
                this.$emit('hide')
            },
            submit(){
                this.form.finish = this.saveCheck()
                if(this.form.finish){
                    this.$emit('save', Object.assign({}, this.form))
                    this.$emit('hide')
                }else{
                    return
                }
                this.$nextTick(() => {
                    document.querySelector(`#cc`).scrollIntoView({
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
                this.form = {
                    finish: false,
                    callPlanId: this.scheduleId,
                    prodName: '诺维乐',
                    prodId: 'RENVEL',
                    tabBasic: {
                        B02: '',
                        B03: '',
                        B04: '',
                        B07: '',
                        B05: '',
                        B01: '',
                        B06: ''
                    },
                    tabDisease: {
                        D26: '',
                        D27: '',
                        D28: '',
                        D18: '',
                        D30: '',
                        D29: '',
                        C04: ''
                    },
                    tabComplication: {
                        C15: [],
                        C14: '',
                        C13: '',
                        C01: '',
                        C02: '',
                        C10: '',
                        C11: '',
                        C12: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T07: '',
                        T06: '',
                        T17: ''
                    }
                }
            }
        },
        mounted() {
        },
        watch: {
            tabActive(newval, oldval) {
                this.activeStep = newval
            },
            'form.tabComplication.C15': {
                handler(newval, oldval) {
                    if (!newval.includes('高血压')) {
                        this.form.tabComplication.C13 = ''
                        this.form.tabComplication.C14 = ''
                    }
                    if (!newval.includes('糖尿病')) {
                        this.form.tabComplication.C01 = ''
                        this.form.tabComplication.C10 = ''
                        this.form.tabComplication.C11 = ''
                        this.form.tabComplication.C12 = ''
                    }
                },
                deep: true,
                immediate: true
            },
            'form.tabComplication.C01': {
                handler(newval, oldval) {
                    if (newval != '仅OAD') {
                        this.form.tabComplication.C02 = ''
                    }
                }

            }
        }
    }
</script>

<style scoped>
    .wrapper {
        padding: 20px;
    }

    .title {
        display: flex;
        flex-direction: row;
        align-items: center;
        /*margin-bottom: 10px;*/
    }

    .title_block {
        background: #ACB318;
        width: 4px;
        height: 20px;
    }

    .title_text {
        font-family: PingFangSC-Semibold;
        font-size: 16px;
        color: #333333;
        letter-spacing: 0.3px;
        text-align: justify;
        line-height: 24px;
        margin-left: 12px;
    }

    .field_title {
        font-family: PingFangSC-Regular;
        font-size: 12px;
        color: #999999;
        letter-spacing: 0.22px;
        text-align: justify;
        line-height: 16px;
    }

    .field_item {
        margin-top: 10px;
    }

    .title_sub {
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #454592;
        letter-spacing: 0.26px;
        text-align: justify;
        margin-top: 20px;
    }

    .submit {
        width: 100%;
        height: 48px;
        display: flex;
        justify-content: center;
        margin-top: 50px;
        margin-bottom: 20px;
    }

    .submit_btn {
        width: 90%;
        height: 48px;
        background: #ACB318;
        border-radius: 2px;
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
    }
    .submit_btn2{
        width: 90%;
        height: 48px;
        background: #454592;
        border-radius: 2px;
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        margin: 0 auto;
    }
    .mt20 {
        margin-top: 20px;
    }

    .van-cell {
        padding: 10px 0px !important;
        border-bottom: 1px solid #ddd;
    }
</style>